﻿using Sunny.UI;
using Sunny.UI.Demo.Forms;

namespace FZRD

{
    public partial class Page4 : UIPage
    {
        public Page4()
        {
            InitializeComponent();

            uiDataGridView1.AddColumn("Column1", "Column1").SetFixedMode(400);
            uiDataGridView1.AddColumn("Column2", "Column2").SetFixedMode(400);
            uiDataGridView1.AddColumn("Column3", "Column3").SetFixedMode(400);
            uiDataGridView1.AddColumn("Column4", "Column4").SetFixedMode(400);
        }
        public override void Init()
        {
            base.Init();

            List<Data> datas = new List<Data>();
            for (int i = 0; i < 3650; i++)
            {
                Data data = new Data();
                data.Column1 = "Data" + i.ToString("D2");
                data.Column2 = i.Mod(2) == 0 ? "A" : "B";
                data.Column3 = "编辑";
                data.Column4 = i.Mod(4) == 0;
                datas.Add(data);
            }

            uiPagination1.DataSource = datas;
            uiPagination1.ActivePage = 1;
        }

        public class Data
        {
            public string Column1 { get; set; }

            public string Column2 { get; set; }

            public string Column3 { get; set; }

            public bool Column4 { get; set; }

            public override string ToString()
            {
                return Column1;
            }
        }

        private void uiPagination1_PageChanged(object sender, object pagingSource, int pageIndex, int count)
        {
            uiDataGridView1.DataSource = pagingSource;
        }

        private void btnAdd_Click(object sender, System.EventArgs e)
        {
            FAddForm frm = new FAddForm();
            frm.ShowDialog();
            if (frm.IsOK)
            {
                this.ShowSuccessDialog(frm.AddRaster.ToString());
            }

            frm.Dispose();
        }

        private void btnEdit_Click(object sender, System.EventArgs e)
        {
            EditRaster editRaster = new EditRaster();
            editRaster.RasterID = 1;
            editRaster.RasterName = "温度传感器1";
            editRaster.RasterType = 2;
            editRaster.ChannelIndex = 0;
            editRaster.RasterIndex = 0;
            editRaster.WaveCount = 1;
            editRaster.RasterDes = "测试温度传感器1";
            editRaster.Expression = "(实时波长值 – 初始状态波长值 )*1000/(转换系数 10pm/℃) + 初始温度";

            FEditForm frm = new FEditForm();
            frm.EditRaster = editRaster;
            frm.ShowDialog();
            if (frm.IsOK)
            {
                this.ShowSuccessDialog(frm.EditRaster.ToString());
            }

            frm.Dispose();
        }

    }
}